package com.medicine.controller;

import java.io.IOException;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import pagination.Page;
import po.Cgdd;
import po.Rkxx;
import po.Ypkcxx;
import po.Ypxx;
import po.Zgxx;
import requestvo.CgddReqVo;
import requestvo.PurchaseReqVo;
import requestvo.RkxxReqVo;
import requestvo.YpkcxxReqVo;

import com.medicine.dao.impl.YpkcxxDao;
import com.medicine.dao.impl.RkxxDao;
import com.medicine.service.impl.RkxxService;
import common.Common;

@Controller
public class PurchaseController extends BaseController{	
	@RequestMapping("/sbcgsq")
	public void findsbcgxx(String[] sb_name,PurchaseReqVo purchaseReqVo,HttpServletRequest request,HttpServletResponse response) throws IOException{
		String[] equipmentName=request.getParameterValues("sb_name");
		//String[] nameStrings=sb_name;
		/*生成采购申请流水号*/
		Common common=new Common();
		String orderid=common.getOrderid();
		for(int i=0;i<equipmentName.length;i++){
			
		}
		Page<PurchaseReqVo> page=purchaseService.findsbcgxx(purchaseReqVo);
		JSONObject jsonObject=new JSONObject();
		jsonObject.element("rows", page.getResults());
		jsonObject.element("total", page.getTotalRecord());
		response.setCharacterEncoding("UTF-8");  
		response.setContentType("application/json; charset=utf-8");  
		response.getWriter().print(jsonObject.toString());
		
	}
	@RequestMapping("/applyPurchase")
	public void applyPurchase(String[] sb_name,PurchaseReqVo purchaseReqVo,HttpServletRequest request,HttpServletResponse response) throws IOException{
		String[] equipmentName=request.getParameterValues("sb_name");
		//String[] nameStrings=sb_name;
		/*生成采购申请流水号*/
		Common common=new Common();
		String orderid=common.getOrderid();
		purchaseReqVo.setOrderid(orderid);
		for(int i=0;i<equipmentName.length;i++){
			purchaseReqVo.setSb_name(equipmentName[i]);
			purchaseService.addEquipment(purchaseReqVo);
		}
	}
	@RequestMapping("/updatesbcgxx")
	public void updatesbcgxx(PurchaseReqVo purchaseReqVo,HttpServletResponse response) throws IOException{
		
		/*purchaseService.updatesbcgxx(purchaseReqVo);
		response.sendRedirect("sb_caigou.html");*/
	}
	
	@RequestMapping("/addsbcgxx")
	public void addsbcgxx(Cgdd cgdd,HttpServletResponse response,HttpSession session) throws IOException{
		Zgxx zgxx=(Zgxx) session.getAttribute("user");
//		cgdd.setZgbm(zgxx.getZgbm());
		/*purchaseService.addsbcgxx(cgdd);*/
		response.sendRedirect("sb_caigou.html");
	}
	
	@RequestMapping("/delsbcgxx")
	public void delsbcgxx(String ids,HttpServletResponse response) throws IOException{
		String[] id=ids.split(",");
		Integer[] integers=new Integer[id.length];
		for(int i=0;i<id.length;++i)
			integers[i]=Integer.parseInt(id[i]);
		/*purchaseService.delsbcgxx(integers);*/
		response.sendRedirect("sb_caigou.html");
	}
	
	
}
